#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int searchmiddle(vector<int> A, vector<int> B)
    {
        int l1 = 0, r1 = A.size() - 1;
        int l2 = 0, r2 = A.size() - 1;
        while (r1>l1 && r2>l2)
        {
            int middle1 = (l1+r1)/2;
            int middle2 = (l2+r2)/2;
            if(A[middle1]<B[middle2])
            {
                l1 = middle1 ;
                r2 = middle2 ;
            }
            else if(A[middle1]>B[middle2])
            {
                r1 = middle1 ;
                l2 = middle2 ;
            }
            else    return A[middle1];
        }
        if(l1 == r1 || l2 == r2)
        {
            return max(A[r1], B[r2]);
        }
        return 0;
    }
};

int main()
{
    vector<int> A = {1, 3, 5, 7, 9};
    vector<int> B = {2, 4, 6, 8, 10};
    Solution sol;
    cout << sol.searchmiddle(A, B);
}